package org.robotfish.utils;

import static org.junit.Assert.*;

import java.io.IOException;
import java.text.ParseException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;

import org.junit.Test;
import org.xml.sax.SAXException;

public class ConfigTest {

	double [] x = {-0.5, -0.50000006003001, -0.50000024012006, -0.50000054027014, -0.50000096048024, -0.50000150075038, -0.50000216108054, -0.50000294147074, -0.50000384192096, -0.50000486243122, -0.5000060030015
	, -0.50000726363182, -0.50000864432216, -0.50001014507254, -0.50001176588294, -0.50001350675338, -0.50001536768384, -0.50001734867434, -0.50001944972486, -0.50002167083542, -0.500024012006
	, -0.50002647323662, -0.50002905452726, -0.50003175587794, -0.50003457728864, -0.50003751875938, -0.50004058029015, -0.50004376188094, -0.50004706353177, -0.50005048524262, -0.50005402701351
	, -0.50005768884442, -0.50006147073537, -0.50006537268634, -0.50006939469735, -0.50007353676838, -0.50007779889945, -0.50008218109055, -0.50008668334167, -0.50009130565283, -0.50009604802401
	, -0.50010091045523, -0.50010589294647, -0.50011099549775, -0.50011621810905, -0.50012156078039, -0.50012702351176, -0.50013260630315, -0.50013830915458, -0.50014413206603, -0.50015007503752
	, -0.50015613806903, -0.50016232116058, -0.50016862431216, -0.50017504752376, -0.5001815907954, -0.50018825412706, -0.50019503751876, -0.50020194097049, -0.50020896448224, -0.50021610805403
	, -0.50022337168584, -0.50023075537769, -0.50023825912956, -0.50024588294147, -0.50025362681341, -0.50026149074537, -0.50026947473737, -0.50027757878939, -0.50028580290145, -0.50029414707354
	, -0.50030261130565, -0.5003111955978, -0.50031989994997, -0.50032872436218, -0.50033766883442, -0.50034673336668, -0.50035591795898, -0.50036522261131, -0.50037464732366, -0.50038419209605
	, -0.50039385692846, -0.50040364182091, -0.50041354677339, -0.50042357178589, -0.50043371685843, -0.500443981991, -0.50045436718359, -0.50046487243622, -0.50047549774887, -0.50048624312156
	, -0.50049710855428, -0.50050809404702, -0.5005191995998, -0.50053042521261, -0.50054177088544, -0.50055323661831, -0.50056482241121, -0.50057652826413, -0.50058835417709, -0.50060030015008
	, -0.50061236618309, -0.50062455227614, -0.50063685842921, -0.50064928464232, -0.50066183091546, -0.50067449724862, -0.50068728364182, -0.50070019009505, -0.5007132166083, -0.50072636318159
	, -0.50073962981491, -0.50075301650825, -0.50076652326163, -0.50078015007504, -0.50079389694847, -0.50080776388194, -0.50082175087544, -0.50083585792896, -0.50085008504252, -0.50086443221611
	, -0.50087889944972, -0.50089348674337, -0.50090819409705, -0.50092302151076, -0.50093796898449, -0.50095303651826, -0.50096822411206, -0.50098353176588, -0.50099895947974, -0.50101450725363
	, -0.50103017508754, -0.50104596298149, -0.50106187093547, -0.50107789894947, -0.50109404702351, -0.50111031515758, -0.50112670335168, -0.5011432116058, -0.50115983991996, -0.50117658829415
	, -0.50119345672836, -0.50121044522261, -0.50122755377689, -0.5012447823912, -0.50126213106553, -0.5012795997999, -0.5012971885943, -0.50131489744872, -0.50133272636318, -0.50135067533767
	, -0.50136874437219, -0.50138693346673, -0.50140524262131, -0.50142367183592, -0.50144222111056, -0.50146089044522, -0.50147967983992, -0.50149858929465, -0.5015176188094, -0.50153676838419
	, -0.50155603801901, -0.50157542771386, -0.50159493746873, -0.50161456728364, -0.50163431715858, -0.50165418709355, -0.50167417708854, -0.50169428714357, -0.50171451725863, -0.50173486743372
	, -0.50175533766883, -0.50177592796398, -0.50179663831916, -0.50181746873437, -0.5018384192096, -0.50185948974487, -0.50188068034017, -0.5019019909955, -0.50192342171086, -0.50194497248624
	, -0.50196664332166, -0.50198843421711, -0.50201034517259, -0.50203237618809, -0.50205452726363, -0.5020767983992, -0.5020991895948, -0.50212170085043, -0.50214433216608, -0.50216708354177
	, -0.50218995497749, -0.50221294647324, -0.50223605802901, -0.50225928964482, -0.50228264132066, -0.50230611305653, -0.50232970485243, -0.50235341670835, -0.50237724862431, -0.5024012006003
	, -0.50242527263632, -0.50244946473237, -0.50247377688844, -0.50249820910455, -0.50252276138069, -0.50254743371686, -0.50257222611306, -0.50259713856928, -0.50262217108554, -0.50264732366183
	, -0.50267259629815, -0.5026979889945, -0.50272350175088, -0.50274913456728, -0.50277488744372, -0.50280076038019, -0.50282675337669, -0.50285286643322, -0.50287909954977, -0.50290545272636
	, -0.50293192596298, -0.50295851925963, -0.50298523261631, -0.50301206603302, -0.50303901950975, -0.50306609304652, -0.50309328664332, -0.50312060030015, -0.50314803401701, -0.5031755877939
	, -0.50320326163082, -0.50323105552776, -0.50325896948474, -0.50328700350175, -0.50331515757879, -0.50334343171586, -0.50337182591296, -0.50340034017009, -0.50342897448724, -0.50345772886443
	, -0.50348660330165, -0.5035155977989, -0.50354471235618, -0.50357394697349, -0.50360330165083, -0.50363277638819, -0.50366237118559, -0.50369208604302, -0.50372192096048, -0.50375187593797
	, -0.50378195097549, -0.50381214607304, -0.50384246123062, -0.50387289644822, -0.50390345172586, -0.50393412706353, -0.50396492246123, -0.50399583791896, -0.50402687343672, -0.50405802901451
	, -0.50408930465233, -0.50412070035018, -0.50415221610805, -0.50418385192596, -0.5042156078039, -0.50424748374187, -0.50427947973987, -0.5043115957979, -0.50434383191596, -0.50437618809405
	, -0.50440866433217, -0.50444126063032, -0.50447397698849, -0.5045068134067, -0.50453976988494, -0.50457284642321, -0.50460604302151, -0.50463935967984, -0.5046727963982, -0.50470635317659
	, -0.50474003001501, -0.50477382691346, -0.50480774387194, -0.50484178089045, -0.50487593796898, -0.50491021510755, -0.50494461230615, -0.50497912956478, -0.50501376688344, -0.50504852426213
	, -0.50508340170085, -0.5051183991996, -0.50515351675838, -0.50518875437719, -0.50522411205603, -0.5052595897949, -0.5052951875938, -0.50533090545273, -0.50536674337169, -0.50540270135068
	, -0.50543877938969, -0.50547497748874, -0.50551129564782, -0.50554773386693, -0.50558429214607, -0.50562097048524, -0.50565776888444, -0.50569468734367, -0.50573172586293, -0.50576888444222
	, -0.50580616308154, -0.50584356178089, -0.50588108054027, -0.50591871935968, -0.50595647823912, -0.50599435717859, -0.50603235617809, -0.50607047523762, -0.50610871435718, -0.50614707353677
	, -0.50618555277639, -0.50622415207604, -0.50626287143572, -0.50630171085543, -0.50634067033517, -0.50637974987494, -0.50641894947474, -0.50645826913457, -0.50649770885443, -0.50653726863432
	, -0.50657694847424, -0.50661674837419, -0.50665666833417, -0.50669670835418, -0.50673686843422, -0.50677714857429, -0.50681754877439, -0.50685806903452, -0.50689870935468, -0.50693946973487
	, -0.50698035017509, -0.50702135067534, -0.50706247123562, -0.50710371185593, -0.50714507253627, -0.50718655327664, -0.50722815407704, -0.50726987493747, -0.50731171585793, -0.50735367683842
	, -0.50739575787894, -0.50743795897949, -0.50748028014007, -0.50752272136068, -0.50756528264132, -0.50760796398199, -0.50765076538269, -0.50769368684342, -0.50773672836418, -0.50777988994497
	, -0.50782317158579, -0.50786657328664, -0.50791009504752, -0.50795373686843, -0.50799749874937, -0.50804138069035, -0.50808538269135, -0.50812950475238, -0.50817374687344, -0.50821810905453
	, -0.50826259129565, -0.5083071935968, -0.50835191595798, -0.50839675837919, -0.50844172086043, -0.5084868034017, -0.508532006003, -0.50857732866433, -0.50862277138569, -0.50866833416708
	, -0.5087140170085, -0.50875981990996, -0.50880574287144, -0.50885178589295, -0.50889794897449, -0.50894423211606, -0.50899063531766, -0.50903715857929, -0.50908380190095, -0.50913056528264
	, -0.50917744872436, -0.50922445222611, -0.50927157578789, -0.5093188194097, -0.50936618309155, -0.50941366683342, -0.50946127063532, -0.50950899449725, -0.50955683841921, -0.5096048024012
	, -0.50965288644322, -0.50970109054527, -0.50974941470735, -0.50979785892946, -0.50984642321161, -0.50989510755378, -0.50994391195598, -0.50999283641821, -0.51004188094047, -0.51009104552276
	, -0.51014033016508, -0.51018973486743, -0.51023925962981, -0.51028890445223, -0.51033866933467, -0.51038855427714, -0.51043855927964, -0.51048868434217, -0.51053892946473, -0.51058929464732
	, -0.51063977988995, -0.5106903851926, -0.51074111055528, -0.51079195597799, -0.51084292146073, -0.5108940070035, -0.5109452126063, -0.51099653826913, -0.511047983992, -0.51109954977489
	, -0.51115123561781, -0.51120304152076, -0.51125496748374, -0.51130701350675, -0.51135917958979, -0.51141146573287, -0.51146387193597, -0.5115163981991, -0.51156904452226, -0.51162181090545
	, -0.51167469734867, -0.51172770385193, -0.51178083041521, -0.51183407703852, -0.51188744372186, -0.51194093046523, -0.51199453726863, -0.51204826413207, -0.51210211105553, -0.51215607803902
	, -0.51221016508254, -0.51226437218609, -0.51231869934967, -0.51237314657329, -0.51242771385693, -0.5124824012006, -0.5125372086043, -0.51259213606803, -0.5126471835918, -0.51270235117559
	, -0.51275763881941, -0.51281304652326, -0.51286857428714, -0.51292422211106, -0.512979989995, -0.51303587793897, -0.51309188594297, -0.513148014007, -0.51320426213107, -0.51326063031516
	, -0.51331711855928, -0.51337372686343, -0.51343045522761, -0.51348730365183, -0.51354427213607, -0.51360136068034, -0.51365856928464, -0.51371589794897, -0.51377334667334, -0.51383091545773
	, -0.51388860430215, -0.5139464132066, -0.51400434217109, -0.5140623911956, -0.51412056028014, -0.51417884942471, -0.51423725862931, -0.51429578789395, -0.51435443721861, -0.5144132066033
	, -0.51447209604802, -0.51453110555278, -0.51459023511756, -0.51464948474237, -0.51470885442721, -0.51476834417209, -0.51482795397699, -0.51488768384192, -0.51494753376688, -0.51500750375188
	, -0.5150675937969, -0.51512780390195, -0.51518813406703, -0.51524858429215, -0.51530915457729, -0.51536984492246, -0.51543065532766, -0.5154915857929, -0.51555263631816, -0.51561380690345
	, -0.51567509754877, -0.51573650825413, -0.51579803901951, -0.51585968984492, -0.51592146073037, -0.51598335167584, -0.51604536268134, -0.51610749374687, -0.51616974487244, -0.51623211605803
	, -0.51629460730365, -0.5163572186093, -0.51641994997499, -0.5164828014007, -0.51654577288644, -0.51660886443222, -0.51667207603802, -0.51673540770385, -0.51679885942971, -0.51686243121561
	, -0.51692612306153, -0.51698993496748, -0.51705386693347, -0.51711791895948, -0.51718209104552, -0.5172463831916, -0.5173107953977, -0.51737532766383, -0.51743997999, -0.51750475237619
	, -0.51756964482241, -0.51763465732866, -0.51769978989495, -0.51776504252126, -0.5178304152076, -0.51789590795398, -0.51796152076038, -0.51802725362681, -0.51809310655328, -0.51815907953977
	, -0.51822517258629, -0.51829138569285, -0.51835771885943, -0.51842417208604, -0.51849074537269, -0.51855743871936, -0.51862425212606, -0.5186911855928, -0.51875823911956, -0.51882541270635
	, -0.51889270635318, -0.51896012006003, -0.51902765382691, -0.51909530765383, -0.51916308154077, -0.51923097548774, -0.51929898949475, -0.51936712356178, -0.51943537768884, -0.51950375187594
	, -0.51957224612306, -0.51964086043022, -0.5197095947974, -0.51977844922461, -0.51984742371186, -0.51991651825913, -0.51998573286643, -0.52005506753377, -0.52012452226113, -0.52019409704852
	, -0.52026379189595, -0.5203336068034, -0.52040354177089, -0.5204735967984, -0.52054377188594, -0.52061406703352, -0.52068448224112, -0.52075501750875, -0.52082567283642, -0.52089644822411
	, -0.52096734367184, -0.52103835917959, -0.52110949474737, -0.52118075037519, -0.52125212606303, -0.52132362181091, -0.52139523761881, -0.52146697348674, -0.52153882941471, -0.5216108054027
	, -0.52168290145073, -0.52175511755878, -0.52182745372686, -0.52189990995498, -0.52197248624312, -0.5220451825913, -0.5221179989995, -0.52219093546773, -0.522263991996, -0.52233716858429
	, -0.52241046523262, -0.52248388194097, -0.52255741870935, -0.52263107553777, -0.52270485242621, -0.52277874937469, -0.52285276638319, -0.52292690345173, -0.52300116058029, -0.52307553776888
	, -0.52315003501751, -0.52322465232616, -0.52329938969485, -0.52337424712356, -0.52344922461231, -0.52352432216108, -0.52359953976988, -0.52367487743872, -0.52375033516758, -0.52382591295648
	, -0.5239016108054, -0.52397742871436, -0.52405336668334, -0.52412942471236, -0.5242056028014, -0.52428190095048, -0.52435831915958, -0.52443485742871, -0.52451151575788, -0.52458829414707
	, -0.5246651925963, -0.52474221110555, -0.52481934967484, -0.52489660830415, -0.5249739869935, -0.52505148574287, -0.52512910455228, -0.52520684342171, -0.52528470235118, -0.52536268134067
	, -0.5254407803902, -0.52551899949975, -0.52559733866933, -0.52567579789895, -0.52575437718859, -0.52583307653827, -0.52591189594797, -0.52599083541771, -0.52606989494747, -0.52614907453727
	, -0.52622837418709, -0.52630779389695, -0.52638733366683, -0.52646699349675, -0.52654677338669, -0.52662667333667, -0.52670669334667, -0.52678683341671, -0.52686709354677, -0.52694747373687
	, -0.52702797398699, -0.52710859429715, -0.52718933466733, -0.52727019509755, -0.52735117558779, -0.52743227613807, -0.52751349674837, -0.52759483741871, -0.52767629814907, -0.52775787893947
	, -0.52783957978989, -0.52792140070035, -0.52800334167084, -0.52808540270135, -0.5281675837919, -0.52824988494247, -0.52833230615308, -0.52841484742371, -0.52849750875438, -0.52858029014507
	, -0.5286631915958, -0.52874621310655, -0.52882935467734, -0.52891261630815, -0.528995997999, -0.52907949974987, -0.52916312156078, -0.52924686343172, -0.52933072536268, -0.52941470735368
	, -0.5294988094047, -0.52958303151576, -0.52966737368684, -0.52975183591796, -0.5298364182091, -0.52992112056028, -0.53000594297149, -0.53009088544272, -0.53017594797399, -0.53026113056528
	, -0.53034643321661, -0.53043185592796, -0.53051739869935, -0.53060306153077, -0.53068884442221, -0.53077474737369, -0.53086077038519, -0.53094691345673, -0.53103317658829, -0.53111955977989
	, -0.53120606303152, -0.53129268634317, -0.53137942971486, -0.53146629314657, -0.53155327663832, -0.5316403801901, -0.5317276038019, -0.53181494747374, -0.5319024112056, -0.5319899949975
	, -0.53207769884942, -0.53216552276138, -0.53225346673337, -0.53234153076538, -0.53242971485743, -0.5325180190095, -0.53260644322161, -0.53269498749375, -0.53278365182591, -0.53287243621811
	, -0.53296134067034, -0.53305036518259, -0.53313950975488, -0.53322877438719, -0.53331815907954, -0.53340766383192, -0.53349728864432, -0.53358703351676, -0.53367689844922, -0.53376688344172
	, -0.53385698849425, -0.5339472136068, -0.53403755877939, -0.53412802401201, -0.53421860930465, -0.53430931465733, -0.53440014007004, -0.53449108554277, -0.53458215107554, -0.53467333666833
	, -0.53476464232116, -0.53485606803402, -0.5349476138069, -0.53503927963982, -0.53513106553277, -0.53522297148574, -0.53531499749875, -0.53540714357179, -0.53549940970485, -0.53559179589795
	, -0.53568430215108, -0.53577692846423, -0.53586967483742, -0.53596254127064, -0.53605552776388, -0.53614863431716, -0.53624186093047, -0.5363352076038, -0.53642867433717, -0.53652226113057
	, -0.53661596798399, -0.53670979489745, -0.53680374187094, -0.53689780890445, -0.536991995998, -0.53708630315158, -0.53718073036518, -0.53727527763882, -0.53736994497249, -0.53746473236618
	, -0.53755963981991, -0.53765466733367, -0.53774981490745, -0.53784508254127, -0.53794047023512, -0.53803597798899, -0.5381316058029, -0.53822735367684, -0.53832322161081, -0.5384192096048
	, -0.53851531765883, -0.53861154577289, -0.53870789394697, -0.53880436218109, -0.53890095047524, -0.53899765882941, -0.53909448724362, -0.53919143571786, -0.53928850425213, -0.53938569284642
	, -0.53948300150075, -0.53958043021511, -0.53967797898949, -0.53977564782391, -0.53987343671836, -0.53997134567284, -0.54006937468734, -0.54016752376188, -0.54026579289645, -0.54036418209105
	, -0.54046269134567, -0.54056132066033, -0.54066007003502, -0.54075893946973, -0.54085792896448, -0.54095703851926, -0.54105626813407, -0.5411556178089, -0.54125508754377, -0.54135467733867
	, -0.5414543871936, -0.54155421710855, -0.54165416708354, -0.54175423711856, -0.54185442721361, -0.54195473736868, -0.54205516758379, -0.54215571785893, -0.5422563881941, -0.54235717858929
	, -0.54245808904452, -0.54255911955978, -0.54266027013507, -0.54276154077039, -0.54286293146573, -0.54296444222111, -0.54306607303652, -0.54316782391196, -0.54326969484742, -0.54337168584292
	, -0.54347379689845, -0.54357602801401, -0.54367837918959, -0.54378085042521, -0.54388344172086, -0.54398615307654, -0.54408898449225, -0.54419193596798, -0.54429500750375, -0.54439819909955
	, -0.54450151075538, -0.54460494247124, -0.54470849424712, -0.54481216608304, -0.54491595797899, -0.54501986993497, -0.54512390195098, -0.54522805402701, -0.54533232616308, -0.54543671835918
	, -0.54554123061531, -0.54564586293147, -0.54575061530765, -0.54585548774387, -0.54596048024012, -0.5460655927964, -0.54617082541271, -0.54627617808904, -0.54638165082541, -0.54648724362181
	, -0.54659295647824, -0.5466987893947, -0.54680474237119, -0.5469108154077, -0.54701700850425, -0.54712332166083, -0.54722975487744, -0.54733630815408, -0.54744298149075, -0.54754977488744
	, -0.54765668834417, -0.54776372186093, -0.54787087543772, -0.54797814907454, -0.54808554277139, -0.54819305652826, -0.54830069034517, -0.54840844422211, -0.54851631815908, -0.54862431215608
	, -0.54873242621311, -0.54884066033017, -0.54894901450725, -0.54905748874437, -0.54916608304152, -0.5492747973987, -0.54938363181591, -0.54949258629315, -0.54960166083042, -0.54971085542771
	, -0.54982017008504, -0.5499296048024, -0.55003915957979, -0.55014883441721, -0.55025862931466, -0.55036854427214, -0.55047857928964, -0.55058873436718, -0.55069900950475, -0.55080940470235
	, -0.55091991995998, -0.55103055527764, -0.55114131065533, -0.55125218609305, -0.5513631815908, -0.55147429714857, -0.55158553276638, -0.55169688844422, -0.55180836418209, -0.55191995997999
	, -0.55203167583792, -0.55214351175588, -0.55225546773387, -0.55236754377189, -0.55247973986993, -0.55259205602801, -0.55270449224612, -0.55281704852426, -0.55292972486243, -0.55304252126063
	, -0.55315543771886, -0.55326847423712, -0.55338163081541, -0.55349490745373, -0.55360830415208, -0.55372182091046, -0.55383545772886, -0.5539492146073, -0.55406309154577, -0.55417708854427
	, -0.5542912056028, -0.55440544272136, -0.55451979989995, -0.55463427713857, -0.55474887443722, -0.5548635917959, -0.55497842921461, -0.55509338669335, -0.55520846423212, -0.55532366183092
	, -0.55543897948974, -0.5555544172086, -0.55566997498749, -0.55578565282641, -0.55590145072536, -0.55601736868434, -0.55613340670335, -0.55624956478239, -0.55636584292146, -0.55648224112056
	, -0.55659875937969, -0.55671539769885, -0.55683215607804, -0.55694903451726, -0.55706603301651, -0.55718315157579, -0.5573003901951, -0.55741774887444, -0.55753522761381, -0.55765282641321
	, -0.55777054527264, -0.5578883841921, -0.55800634317159, -0.55812442221111, -0.55824262131066, -0.55836094047024, -0.55847937968984, -0.55859793896948, -0.55871661830915, -0.55883541770885
	, -0.55895433716858, -0.55907337668834, -0.55919253626813, -0.55931181590795, -0.5594312156078, -0.55955073536768, -0.55967037518759, -0.55979013506753, -0.5599100150075, -0.5600300150075};


	
	@Test
	public void test() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, ParseException {

//		"D:\Users\Mart\workspace\fishrobot\robotfish\data\configuration015.xml"

		Config c = new Config("data/configuration015.xml");
		
		System.out.println(c.select1String("//*[Name='NoseMotion']/*[Name='Nose']//*[Name='x']/Val"));
		
		double[] dl = {12};
//		try {
			dl = c.selectDouble("//*[Name='NoseMotion']/*[Name='Nose']//*[Name='x']/Val");
			for (int i = 0;i<dl.length;i++) {
/*				System.out.print((i+1));
				System.out.print(") ");
				System.out.println(dl[i]);*/
/*				System.out.print(", ");
				System.out.print(dl[i]);
				if ((i % 10)==0)
					System.out.println();*/
			}
			System.out.println(dl.length);
/*		} catch (Exception e) {
			e.printStackTrace();
			//System.out.println(e);
			// TODO: handle exception
		}*/
		
		assertArrayEquals(dl, x, 1E-9);
		
//		System.out.println(dl[0]);
		
	//	fail("Not yet implemented");
	}

}
